from selenium import webdriver
from selenium.webdriver.common.by import By
import time

driver=webdriver.Firefox()
driver.get('https://www.baidu.com/')
# driver.get('https://mail.163.com/')

# driver.switch_to.frame(driver.find_element(By.XPATH,'//iframe[starts_with(@id,x-URS-iframe17528)]'))
#
# driver.find_element(By.XPATH,'//input[starts_with(@id,auto-id-17528)]').send_keys('111111')

# 1相对路径
# driver.find_element(By.XPATH,'//*[@id="kw"]').send_keys('xpath定位1')
# 2绝对路径
# driver.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[6]/div/div/form/span[1]/input').send_keys('xpath定位2')
# 3属性
# driver.find_element(By.XPATH,'//input[@name="wd"]').send_keys('xpath定位3')
# 4逻辑 and
# driver.find_element(By.XPATH,'//input[@name="wd" and id="kw"]').send_keys('xpath定位4')
# 5逻辑 or
# driver.find_element(By.XPATH,
# '//input[@class="s_ipt" or id="kw"]')
# .send_keys('xpath定位5')

# driver.find_element(By.XPATH,
# '//input[contains(@id,"k")]')
# .send_keys('xpath定位7')
# driver.find_element(By.XPATH,
# '//input[contains(@id,"w")]')
# .send_keys('xpath定位8')
# driver.find_element(By.XPATH,
# '//input[contains(@name,"w")]')
# .send_keys('xpath定位9')
driver.find_element(By.LINK_TEXT
                    ,'新闻').click()
time.sleep(5)
driver.switch_to.window(driver.
                        window_handles[-1])
time.sleep(5)
driver.find_element(By.XPATH,
                    '//a[contains(text(),"时政微观察")]').click()

time.sleep(5)














driver.quit()